# -*- coding: utf-8 -*-：
from flask import Flask, request, Response, jsonify, make_response
import spring_lamb
import cal_grazeFtrq

server = Flask(__name__)


@server.route('/lamb', methods=['GET', 'POST'])
def reg():
    num = request.values.get('num')
    price = request.values.get('price')
    gancao_price = request.values.get('gancao_price')
    jingliao_price = request.values.get('jingliao_price')
    gongzi = request.values.get('gongzi')
    jichu_money = request.values.get('jichu_money')
    para = [num, price, gancao_price, jingliao_price, gongzi, jichu_money]
    value_default = [300, 24, 1.3, 4.5, 4500, 75000]

    for i, value in enumerate(para):
        if not value:
            para[i] = value_default[i]

    c = spring_lamb.main(float(para[0]), float(para[1]), float(para[2]), float(para[3]), float(para[4]), float(para[5]))

    # c = spring_lamb.main(float(num), float(price), float(gancao_price), float(jingliao_price), float(gongzi), float(jichu_money))
    # c = spring_lamb.main(num)

    #
    response = make_response(jsonify(c))
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'POST'
    response.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
    return response



@server.route('/mapk', methods=['GET', 'POST'])
def mapk():
    id = request.values.get('name_id')
    c = cal_grazeFtrq.main(id)
    print c
    # return c
    response = make_response(jsonify(c))
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'POST'
    response.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
    return response


@server.route('/login', methods=['GET', 'POST'])
def login():
    return 'nihao'


server.run(debug=True, host='0.0.0.0', port=int("5005"))
